package com.d0330;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class TestMethod {

    public static void main(String[] args){
        try {
            Class clazz=Account.class;
            //获得Method对象,方法名是save,参数是double类型
            Method method = clazz.getMethod("save",double.class);

            //创建对象
            Account account  = (Account)clazz.newInstance();
            System.out.println(account.getBalance());
            method.invoke(account,new Double(2000));
            System.out.println(account.getBalance());
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
    }
}
